﻿
namespace SuperMarieApi.App.Controllers.Tool.Common
{
    public class CurrentUser
    {
        /// <summary>
        /// 是否登录
        /// </summary>
        /// <returns></returns>
        public static bool IsLogin()
        {
            return CookieHelper.GetCookie("loginInfo").Length > 10;
        }

        /// <summary>
        /// 获取用户编号ID
        /// </summary>
        public static int LoginId
        {
            get
            {
                return int.Parse(CookieHelper.GetCookie("loginInfo", "id"));
            }
        }


        /// <summary>
        /// 登录人用户ID
        /// </summary>
        public static string LoginUserId
        {
            get
            {
                return CookieHelper.GetCookie("loginInfo", "USER_ID");
            }
        }

      

        /// <summary>
        /// 权限ID
        /// </summary>
        public static int LoginPRIV
        {
            get
            {
                return int.Parse(CookieHelper.GetCookie("loginInfo", "USER_PRIV"));
            }
        }

        /// <summary>
        /// 用户区域ID
        /// </summary>
        public static string AreaID
        {
            get
            {
                return CookieHelper.GetCookie("loginInfo", "AreaID");
            }
        }


        /// <summary>
        /// 获取跨域脚本，主要用于EasyUI的Form方式上传文件
        /// </summary>
        public static string GetCrossDomainScript
        {
            get
            {
                string script = "<Script>";
                script += "function getDomain() {";
                script += @"if (/^(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)$/i.test(location.hostname)) {";
                script += "return location.hostname;";
                script += "} else {";
                script += @"return location.hostname.match(/([\w-]+\.com)$/g)[0];";
                script += "}";
                script += "}";
                script += "document.domain = getDomain();";
                script += "</Script>";
                return script;
            }
        }
    }
}